<script setup lang="ts">
// // 获取路由参数
import { useRoute, useRouter } from 'vue-router'; // useRouter

import { useAccessStore } from '@vben/stores';

import { message } from 'ant-design-vue';

import { bindShopByDly } from '#/api';

const route = useRoute();
const router = useRouter();
const { binddy } = route.query;
// const jump = false;
const accessStore = useAccessStore();
function gotoOuer() {
  // window.location.href = 'https://doulingyang.cn?isinit=1';
  router.replace({
    path: '/home/index',
    // path: '/getgoods/1688-air',
    // path: '/getgoods/1688-strict-selection',
  });
}
if (binddy) {
  bindShopByDly({ param_json: binddy as string })
    .then(async (res) => {
      message.warning('授权成功');
      // console.log(res);
      if (res.access_token && res.refresh_token) {
        accessStore.setAccessToken(res.access_token);
        accessStore.setRefreshToken(res.refresh_token);
        setTimeout(() => {
          gotoOuer();
        }, 500);
        // await router.replace({
        //   path: 'shop-auth-home',
        // });
        return;
      }
      setTimeout(() => {
        gotoOuer();
      }, 500);
      // 跳转到首页
      // await router.replace({
      //   path: '/',
      // });

      // 跳转页面
      // await router.replace({
      //   path: 'shop-auth-home',
      // });
      // setTimeout(() => {
      //   window.location.href = 'https://doulingyang.cn?isinit=1';
      // }, 500);
    })
    .catch(() => {
      gotoOuer();
    });
  // message.warning('授权成功');
} else {
  message.warning('授权失败: code不存在');
  // router.replace({
  //   path: 'shop-auth-home',
  // });
  gotoOuer();
}
</script>

<template>
  <div class="px-4 py-4">正在授权DY 请稍候。。。。。</div>
</template>
